
/***********************************************************************
 * Base class
 * 
 * Implements the base artifact
 *
 * Signature:
 *  public static Base create (String name, Coord position, int energy);
 *  public void install ();
 *  public void destroy ();
 *  public Coord position ();
 *  public String name ();
 *  public void report (String message);
 *  public void changePosition (Coord target);
 *  public boolean isOrbitable ();
 *  public void takeDamage (int damage);
 *  public abstract char display ();
 *  public abstract String toString ();
 *  public int energy ();
 ***********************************************************************/

class Base extends Artifact {

    private int energy;

    protected Base (String n, Coord p, int e) {
	super(n,p);
	this.energy = e;
    }

    public static Base create (String n, Coord p, int e) {
	Base b = new Base(n,p,e);
	b.install();
	return b;
    }

    public char display () {
	return '@';
    }

    public int energy () {
	return this.energy;
    }

    public void takeDamage (int d) {
	if (d<0)
	    throw new IllegalArgumentException("Ship.takeDamage()");
	energy = energy-d;
	if (energy<0) energy=0;
	report("taking damage " + d);
	report("energy down to " + energy);
	if (energy==0) {
	    report("AAAAARRRGHHHH! *BOOM*");
	    destroy();
	}
    }

    public String toString () {
	return "Base " + this.name() + " " + this.position().toString();
    }

    public boolean isOrbitable () {
	return true;
    }

}
